# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.


from odoo import api, fields, models, tools, _


class SaleSplitProduct(models.Model):
    _name = "fp.sale.split.product"
    _description = "FP Sales Split Product"
    _order = 'id'

    code = fields.Char(string='Code')
    name = fields.Char(string='Name')

    has_prodcut = fields.Boolean(
        string="需要转换", required=True, default=False)

    product_id = fields.Many2one(
        'fp.product', 'Product',
        help="详见清单打印格式下, 产品转换")


class SaleSplitGroup(models.Model):
    _name = "fp.sale.split.group"
    _description = "FP Sales Split Group"
    _order = 'id'

    code = fields.Char(string='Code')
    name = fields.Char(string='Name')


class SaleSplit(models.Model):
    _name = "fp.sale.split"
    _description = "FP Sales Split"
    _order = 'sequence, id'

    code = fields.Char(string='Code')
    name = fields.Char(string='Name')
    sequence = fields.Integer(string='Sequence', default=10)
    note = fields.Text(string='Note')

    split_group_ids = fields.Many2many(
        comodel_name='fp.sale.split.group',
        relation='fp_sale_split_to_group_rel',
        column1='split_id',
        column2='split_group_id',
        string='Split Group',
        help="分组")

    linenum_select = fields.Selection(
        selection=[
            ('one', '一行一单'),
            ('all', '全行一单'),
            ('max', '八行一单'),
        ], default='all')

    split_product_id = fields.Many2one(
        'fp.sale.split.product', 'Split Product',
        help="详见清单格式下, 转换的产品")

    note_select = fields.Selection(
        selection=[
            ('no', '不打印备注'),
            ('one', '明细行第一行'),
            ('order', '订单的备注'),
        ], default='no')
